//
//  GYDWBModel.swift
//  Weibo
//
//  Created by 贵永冬 on 16/7/27.
//  Copyright © 2016年 贵永冬. All rights reserved.
//

import UIKit
import SDWebImage
import YYText


class GYDWBModel: NSObject {
    var created_at : String?//微博创建时间
    var id : Int = 0 //微博ID
    var text : String? //微博信息内容
    var source : String? //微博来源
    var reposts_count : Int = 0 //转发数
    var comments_count : Int = 0 //评论数
    var attitudes_count : Int = 0 //表态数
    var original_pic : String? //原始图片地址，没有时不返回此字段
    var user : GYDCommentUser?
    var pic_urls : [[String:String]]?//图片
    var retweeted_status : GYDWBModel?//转发的微博
    var cellHeight : CGFloat = 0.0 //cell 缓存高度
    
    
    static func cacheImageArray(wbModelArray : [AnyObject]?, completeBlock:(()->())) {
        guard let modelArray = wbModelArray else {
            completeBlock()
            return
        }
        //下载组
        let downloadGroup = dispatch_group_create()
        for model in modelArray {
            let wbModel = model as! GYDWBModel
            var newModel : GYDWBModel?
            if wbModel.retweeted_status != nil {
                newModel = wbModel.retweeted_status!
            }else {
                newModel = wbModel
            }
            
            guard let picUrls = newModel!.pic_urls where picUrls.count != 0 else {
                continue
            }
            for dic in picUrls {
                guard let urlStr = dic["thumbnail_pic"] else {
                    continue
                }
                dispatch_group_enter(downloadGroup)
                SDWebImageManager.sharedManager().downloadImageWithURL(NSURL(string: urlStr), options: SDWebImageOptions.HighPriority, progress: nil, completed: { (image, error, _, _, _) in
                    
                    dispatch_group_leave(downloadGroup)
                })
            }
        }
        dispatch_group_notify(downloadGroup, dispatch_get_main_queue()) { 
            completeBlock()
        }
    }
    
    
}


class GYDCommentUser: NSObject {
    var id : Int = 0 //用户UID
    var idstr : String? // 	字符串型的用户UID
    var screen_name : String? //用户昵称
    var profile_image_url : String? //用户头像地址（中图），50×50像素
    var verified : Bool = false //是否是微博认证用户，即加V用户，true：是，false：否
    var verified_type : Int = 0 //认证类型
    var mbrank : Int = -1 //会员等级 1-6
}

